package com.estore.action;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.estore.converter.DateTime;
import com.estore.entity.AgentBanner;
import com.estore.entity.Agent_Product;
import com.estore.entity.Agent_Profile;
import com.estore.entity.Categories;
import com.estore.entity.Discount;
import com.estore.entity.FavoriteProduct;
import com.estore.entity.ProductList;
import com.estore.entity.WebBanner;
import com.estore.entity.WebInterface;
import com.estore.info.AgentProductInfo;
import com.estore.info.BrandInfo;
import com.estore.info.ProductInfo;
import com.estore.info.ShopInfo;
import com.estore.info.SubCatInfo;
import com.estore.manager.ProductManager;
import com.estore.manager.ProfileManager;
import com.estore.manager.ShopManager;
import com.estore.manager.InterfaceManager;
import com.estore.model.InterfaceModel;
import com.estore.model.ProductModel;
import com.estore.model.ProfileModel;
import com.estore.model.ShopModel;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class LinkAction extends ActionSupport implements
		ModelDriven<ProductModel>, ServletRequestAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 950279949692200212L;
	ProductModel productModel = new ProductModel();
	ProfileModel profileModel = new ProfileModel();
	ShopModel shopModel = new ShopModel();
	InterfaceModel interfaceModel = new InterfaceModel();
	
	ProductManager productManager;
	ShopManager shopManager;
	InterfaceManager interfaceManager;
	ProfileManager profileManager;

	DateTime dateTime = new DateTime();

	public HttpServletRequest request;
	private List<SubCatInfo> listSubCat;
	private String sortType;
	private String linkBanner;
	private WebInterface webInterface;
	
	public String listProductByCatShop(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			String catID = request.getParameter("catID");
			String agentID = request.getParameter("agentID");
			List<ProductInfo> listProduct = productManager.getProductByCat(Integer.parseInt(catID));
			List<ProductInfo> listProductInfo = new ArrayList<ProductInfo>();
			List<ProductList> listProductList = shopManager.getAllProductOfShop(Integer.parseInt(agentID));
			if(listProduct != null){
				for(ProductInfo record : listProduct){
					for(ProductList info : listProductList){
						if(info.getProductID() == Integer.parseInt(record.getProductID())){
							listProductInfo.add(record);
						}
					}
				}
			}
			shopModel.setListProduct(listProductInfo);
			shopModel.setShopInterface(shopManager.getShopInterface(Integer.parseInt(agentID)));
			return SUCCESS;
		} else {
			return "banned";
		}
	}
	
	public String endList() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String listID = request.getParameter("listID");
					shopManager.endList(Integer.parseInt(listID));
					// set infomation for page
					
					ShopInfo shopInfo = (ShopInfo) session.get("shopInfo");
					Integer agentID = shopInfo.getAgentID();
					List<ProductList> listShopProduct = shopManager.getAllProductOfShop(shopInfo.getAgentID());
					List<ProductInfo> listProduct = new ArrayList<ProductInfo>();
					for (ProductList record : listShopProduct) {
						ProductInfo productInfo = new ProductInfo();
						Integer listType = record.getListType();
						// get product info of shop
						Agent_Product agentProduct = shopManager.getAgentProductInfo(record.getListID());
						// get discount if have
						Discount discount = shopManager.getDiscount(record.getListID());
						// set product info of web or shop
						if (listType == 0) {
							productInfo = productManager.getProductInfo(record.getProductID(), 0);
						} else {
							productInfo = productManager.getProductInfo(record.getProductID(), agentID);
						}
						// set discount if have
						if(discount != null){
							productInfo.setDiscount(discount.getDiscount());
							float discountPercent = Math.round((float)((((float)agentProduct.getSellingPrice() - (float)discount.getDiscount())  / 
									(float)agentProduct.getSellingPrice())) * 100);
							productInfo.setDiscountPercent(discountPercent);
						}
						productInfo.setSellingPrice(agentProduct.getSellingPrice());
						productInfo.setWarranty(agentProduct.getWarranty());
						productInfo.setCondition(agentProduct.getProductCondition());
						productInfo.setStartDate(agentProduct.getStartDate());
						productInfo.setListID(agentProduct.getListID());
						listProduct.add(productInfo);
					}
					productModel.setListProduct(listProduct);
					return SUCCESS;
				}else if(session.get("role").equals(1) || session.get("role").equals(2)) {
					String listID = request.getParameter("listID");

					Integer agentID = shopManager.getProductList(Integer.parseInt(listID)).getAgentID();
					shopManager.endList(Integer.parseInt(listID));
					List<ProductList> listShopProduct = shopManager.getAllProductOfShop(agentID);
					List<ProductInfo> listProduct = new ArrayList<ProductInfo>();
					for (ProductList record : listShopProduct) {
						ProductInfo productInfo = new ProductInfo();
						Integer listType = record.getListType();
						// get product info of shop
						Agent_Product agentProduct = shopManager.getAgentProductInfo(record.getListID());
						// get discount if have
						Discount discount = shopManager.getDiscount(record.getListID());
						// set product info of web or shop
						if (listType == 0) {
							productInfo = productManager.getProductInfo(record.getProductID(), 0);
						} else {
							productInfo = productManager.getProductInfo(record.getProductID(), agentID);
						}
						// set discount if have
						if(discount != null){
							productInfo.setDiscount(discount.getDiscount());
							float discountPercent = Math.round((float)((((float)agentProduct.getSellingPrice() - (float)discount.getDiscount())  / 
									(float)agentProduct.getSellingPrice())) * 100);
							productInfo.setDiscountPercent(discountPercent);
						}
						productInfo.setSellingPrice(agentProduct.getSellingPrice());
						productInfo.setWarranty(agentProduct.getWarranty());
						productInfo.setCondition(agentProduct.getProductCondition());
						productInfo.setStartDate(agentProduct.getStartDate());
						productInfo.setListID(agentProduct.getListID());
						listProduct.add(productInfo);
					}
					productModel.setListProduct(listProduct);
					
					return "mod";
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}

	
	// click edit discount link by shop
	public String editDiscountLink() throws ParseException {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String productID = request.getParameter("productID");
					ShopInfo shopInfo = (ShopInfo) session.get("shopInfo");
					ProductList productList = shopManager.getProductList(Integer.parseInt(productID), shopInfo.getAgentID());
					Agent_Product agentProduct = shopManager.getAgentProductInfo(productList.getListID());
					Discount discount = shopManager.getDiscount(productList.getListID());
					// if discount unavailable return to make discount page
					if(!shopManager.checkDiscountAvailable(productList.getListID())){

						return "discounterror";
					}
					shopModel.setDiscount(discount);
					shopModel.setAgentProductInfo(agentProduct);
					shopModel.setProductInfo(productManager.getProductInfo(Integer.parseInt(productID), 0));
					Integer dayLeft = dateTime.dayLeft(discount.getEndDate());
					shopModel.setDiscountTimeLeft(dayLeft);
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	// click  make discount link by shop
	public String makeDiscountLink() throws ParseException {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String productID = request.getParameter("productID");
					ShopInfo shopInfo = (ShopInfo) session.get("shopInfo");
					ProductList productList = shopManager.getProductList(Integer.parseInt(productID), shopInfo.getAgentID());
					Agent_Product agentProduct = shopManager.getAgentProductInfo(productList.getListID());
					shopModel.setAgentProductInfo(agentProduct);
					shopModel.setProductInfo(productManager.getProductInfo(Integer.parseInt(productID), 0));
					// if discount available redirect to edit discount page
					if(shopManager.checkDiscountAvailable(productList.getListID())){
						Discount discount = shopManager.getDiscount(productList.getListID());
						shopModel.setDiscount(discount);
						shopModel.setAgentProductInfo(agentProduct);
						shopModel.setProductInfo(productManager.getProductInfo(Integer.parseInt(productID), 0));
						
						Integer dayLeft = dateTime.dayLeft(discount.getEndDate());
						shopModel.setDiscountTimeLeft(dayLeft);
						return "discountavail";
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String agentSellingProduct(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			String productID = request.getParameter("productID");
			List<AgentProductInfo> listAgentProductInfo = shopManager.getListAgentSellingProduct(Integer.parseInt(productID));
			shopModel.setProductInfo(productManager.getProductInfo(Integer.parseInt(productID), 0));
			shopModel.setListAgentProduct(listAgentProductInfo);
			setListSubCat(productManager.listSubCatInfo());
			return SUCCESS;
		} else {
			return "banned";
		}
	}
	
	public String detailShopProductLink() throws ParseException {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			String listID = request.getParameter("listID");
			ProductList productList = shopManager.getProductList(Integer.parseInt(listID));
			ProductInfo productInfo = new ProductInfo();
			Discount discount = new Discount();
			// check if shop using product information of website or shop
			if(productList.getListType() == 0){
				productInfo = productManager.getProductInfo(productList.getProductID(), 0);
			}else{
				productInfo = productManager.getProductInfo(productList.getProductID(), productList.getAgentID());
			}
			Agent_Product agentProduct = shopManager.getAgentProductInfo(Integer.parseInt(listID));
			if(shopManager.getDiscount(productList.getListID()) != null){
				discount = shopManager.getDiscount(productList.getListID());
				float discountPercent = Math.round((float)((((float)agentProduct.getSellingPrice() - (float)discount.getDiscount())  / 
						(float)agentProduct.getSellingPrice())) * 100);
				discount.setDiscountPercent(discountPercent);
				Integer dayLeft = dateTime.dayLeft(discount.getEndDate());
				shopModel.setDiscountTimeLeft(dayLeft);
				shopModel.setDiscount(discount);
			}
			productInfo.setListType(productList.getListType());
			shopModel.setProductInfo(productInfo);
			shopModel.setAgentProductInfo(agentProduct);
			shopModel.setAgentID(productList.getAgentID());
			shopModel.setShopInterface(shopManager.getShopInterface(productList.getAgentID()));
			return SUCCESS;
		} else {
			return "banned";
		}
	}
	
	public String productInfoMngLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) { 
					ShopInfo shopInfo = (ShopInfo) session.get("shopInfo");
					
					// check if productID available
					if(request.getParameter("productID") == null){
						Integer agentID = shopInfo.getAgentID();
						List<ProductList> listShopProduct = shopManager.getAllProductOfShop(shopInfo.getAgentID());
						List<ProductInfo> listProduct = new ArrayList<ProductInfo>();
						for (ProductList record : listShopProduct) {
							ProductInfo productInfo = new ProductInfo();
							Integer listType = record.getListType();
							// get product info of shop
							Agent_Product agentProduct = shopManager.getAgentProductInfo(record.getListID());
							if(agentProduct != null){
								
								// get discount if have
								Discount discount = shopManager.getDiscount(record.getListID());
								// set product info of web or shop
								if (listType == 0) {
									productInfo = productManager.getProductInfo(record.getProductID(), 0);
								} else {
									productInfo = productManager.getProductInfo(record.getProductID(), agentID);
								}
								// set discount if have
								if(discount != null){
									productInfo.setDiscount(discount.getDiscount());
									float discountPercent = Math.round((float)((((float)agentProduct.getSellingPrice() - (float)discount.getDiscount())  / 
											(float)agentProduct.getSellingPrice())) * 100);
									productInfo.setDiscountPercent(discountPercent);
								}
								productInfo.setSellingPrice(agentProduct.getSellingPrice());
								productInfo.setWarranty(agentProduct.getWarranty());
								productInfo.setCondition(agentProduct.getProductCondition());
								productInfo.setStartDate(agentProduct.getStartDate());
								productInfo.setListID(agentProduct.getListID());
							}
							listProduct.add(productInfo);
						}
						productModel.setListProduct(listProduct);
						return "productIDNull";
					}
					
					// set info mng page
					String productID = request.getParameter("productID");
					productModel.setProductInfo(productManager.getProductInfo(Integer.parseInt(productID), 0));
					Agent_Product agentProduct = shopManager.getAgentProductInfo(
							shopManager.getProductList(Integer.parseInt(productID), shopInfo.getAgentID()).getListID());
					AgentProductInfo info = new AgentProductInfo(agentProduct.getProductCondition(), agentProduct.getWarranty(), 
							agentProduct.getListID(), agentProduct.getContentOfShop() , 
							agentProduct.getSellingPrice(), agentProduct.getStartDate(),
							shopManager.getProductList(Integer.parseInt(productID), shopInfo.getAgentID()).getListType()); 
					shopModel.setAgentProduct(info);
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String webBannerTitleLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("role") == null) {
			return "login";
		} else{
			if (session.get("role").equals(1)){
				
				interfaceModel.setListBanner(interfaceManager.getListWebBanner());
				
				return SUCCESS;
			} else return ERROR;
		}
	}
	
	public String webProductTypeLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("role") == null) {
			return "login";
		} else{
			if (session.get("role").equals(1)){
				
				setWebInterface(interfaceManager.getWebInterface());
				return SUCCESS;
			} else return ERROR;
		}
	}
	
	public String webBannerMngLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("role") == null) {
			return "login";
		} else{
			if (session.get("role").equals(1)){
					List<WebBanner> listBanner = interfaceManager.getListWebBanner();
					interfaceModel.setListBanner(listBanner);
					int emptyBanner = 5;
					for(WebBanner record : listBanner){
						emptyBanner -= 1;
					}
					List<String> listEmptyBanner = new ArrayList<String>();
					for(int i =0; i < emptyBanner; i ++){
						listEmptyBanner.add("a");
					}
					interfaceModel.setListEmptyBanner(listEmptyBanner);
				return SUCCESS;
			} else return ERROR;
		}
	}
	
	public InterfaceModel getInterfaceModel() {
		return interfaceModel;
	}

	public void setInterfaceModel(InterfaceModel interfaceModel) {
		this.interfaceModel = interfaceModel;
	}

	public String webBannerLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("role") == null) {
			return "login";
		} else{
			if (session.get("role").equals(1)){
				setWebInterface(interfaceManager.getWebInterface());
				return SUCCESS;
			} else return ERROR;
		}
	}
	
	public String webInterfaceMngLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("role") == null) {
			return "login";
		} else{
			if (session.get("role").equals(1)){
				setWebInterface(interfaceManager.getWebInterface());
				return SUCCESS;
			} else return ERROR;
		}
	}
	
	public String deleteShopBanner() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null
				|| session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String agentID = request.getParameter("agentID");
					String linkBanner = request.getParameter("linkBanner");
					
					// delete banner
					shopManager.deleteBanner(Integer.parseInt(agentID), linkBanner);	
					
					// set banner for banner management page
					if(shopManager.listAgentBanner(Integer.parseInt(agentID)) != null){
						shopModel.setListBanner(shopManager.listAgentBanner(Integer.parseInt(agentID)));
						int emptyBanner = 5;
						List<AgentBanner> listBanner = shopManager.listAgentBanner(Integer.parseInt(agentID));
						for(AgentBanner record : listBanner){
							emptyBanner -= 1;
						}
						List<String> listEmptyBanner = new ArrayList<String>();
						for(int i =0; i < emptyBanner; i ++){
							listEmptyBanner.add("a");
						}
						shopModel.setListEmptyBanner(listEmptyBanner);
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String tittleBannerMngLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String agentID = request.getParameter("agentID");
					if(agentID != null){
						if(shopManager.listAgentBanner(Integer.parseInt(agentID)) != null){
							shopModel.setListBanner(shopManager.listAgentBanner(Integer.parseInt(agentID)));
						}
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String bannerMngLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String agentID = request.getParameter("agentID");
					if(agentID != null){
						if(shopManager.listAgentBanner(Integer.parseInt(agentID)) != null){
							shopModel.setListBanner(shopManager.listAgentBanner(Integer.parseInt(agentID)));
							int emptyBanner = 5;
							List<AgentBanner> listBanner = shopManager.listAgentBanner(Integer.parseInt(agentID));
							for(AgentBanner record : listBanner){
								emptyBanner -= 1;
							}
							List<String> listEmptyBanner = new ArrayList<String>();
							for(int i =0; i < emptyBanner; i ++){
								listEmptyBanner.add("a");
							}
							shopModel.setListEmptyBanner(listEmptyBanner);
						}
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String changeTemplateLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String agentID = request.getParameter("agentID");
					if(agentID != null){
						shopModel.setShopInterface(shopManager.getShopInterface(Integer.parseInt(agentID)));
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String changeProductListTypeLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String agentID = request.getParameter("agentID");
					if(agentID != null){
						shopModel.setShopInterface(shopManager.getShopInterface(Integer.parseInt(agentID)));
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String changeFooterLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null
				|| session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String agentID = request.getParameter("agentID");
					if(agentID != null){
						shopModel.setShopInterface(shopManager.getShopInterface(Integer.parseInt(agentID)));
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String changeSidebarShopLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String agentID = request.getParameter("agentID");
					if(agentID != null){
						shopModel.setShopInterface(shopManager.getShopInterface(Integer.parseInt(agentID)));
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String changeBannerShopLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					String agentID = request.getParameter("agentID");
					if(agentID != null){
						shopModel.setShopInterface(shopManager.getShopInterface(Integer.parseInt(agentID)));
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String shopInterfaceLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}
	
	public String shopHomepageLink(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			String agentID = request.getParameter("agentID");
			if(agentID != null){
				shopModel.setAgentID(Integer.parseInt(agentID));
				shopModel.setShopInterface(shopManager.getShopInterface(Integer.parseInt(agentID)));

				// return all product of shop order by last added
				List<ProductList> listShopProduct = shopManager.getAllProductOfShop(Integer.parseInt(agentID));
				List<ProductInfo> listProduct = new ArrayList<ProductInfo>();
				for (ProductList record : listShopProduct) {
					ProductInfo productInfo = new ProductInfo();
					// return if product show web's info or shop's info
					Integer listType = record.getListType();
					Agent_Product agentProduct = shopManager.getAgentProductInfo(record.getListID());
					if (listType == 0) {
						productInfo = productManager.getProductInfo(record.getProductID(), 0);
					} else {
						productInfo = productManager.getProductInfo(record.getProductID(), Integer.parseInt(agentID));
					}
					// set discount if have
					if(shopManager.getDiscount(record.getListID()) != null){
						Discount discount = shopManager.getDiscount(record.getListID());
						productInfo.setDiscount(discount.getDiscount());
						float discountPercent = Math.round((float)((((float)agentProduct.getSellingPrice() - (float)discount.getDiscount())  / 
								(float)agentProduct.getSellingPrice())) * 100);
						productInfo.setDiscountPercent(discountPercent);
					}
					if(agentProduct != null){
						// set shop's product info
						productInfo.setSellingPrice(agentProduct.getSellingPrice());
						productInfo.setWarranty(agentProduct.getWarranty());
						productInfo.setCondition(agentProduct.getProductCondition());
						productInfo.setStartDate(agentProduct.getStartDate());
						productInfo.setListID(agentProduct.getListID());
						listProduct.add(productInfo);
					}
				}
				productModel.setListProduct(listProduct);
				
				// return product type
				String productType = shopManager.getShopInterface(Integer.parseInt(agentID)).getProductList();
				String[] tokens = productType.split("/");
				String type = "";
				for(String record : tokens){
					type = record;
				}
				//return all banner 
				shopModel.setListBanner(shopManager.listAgentBanner(Integer.parseInt(agentID)));
				// return all categories
				listSubCat = productManager.listSubCatInfo();
				if(type.equals("ProductTypeDefault.jsp")){
					return "default";
				}else if(type.equals("ProductType1.jsp")){
					return "type1";
				}
				
				
			}
			return "success";
		} else {
			return "banned";
		}
	}
	
	public String detailMainCategoriesLink(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {
				productModel.setListMainCategories(productManager.getAllMainCategories());
				return SUCCESS;
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}

	}
	
	public String addMainCategoriesLink(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {

				productModel.setListMainCategories(productManager.getAllMainCategories());
				return SUCCESS;
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}

	}
	
	// remove favorite product
			public String removeFavoriteProduct() {
				Map<String, Object> session = ActionContext.getContext().getSession();
				if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

					profileModel.setErrorChangeProfile(null);
					if (session.get("role") == null) {
						return "login";
					} else {
						String userID = session.get("userID").toString();
						String type = request.getParameter("type");
						String productID = request.getParameter("productID");
						if(productID == null){
							
						}else{
							// if type == 1 remove favorite product, if type ==2 remove watching product
							profileManager.removeFavoriteProduct(Integer.parseInt(userID), Integer.parseInt(productID), Integer.parseInt(type));
						}
						List<FavoriteProduct> listFavor = profileManager.getWatchListProduct(Integer.parseInt(userID), Integer.parseInt(type));
						List<ProductInfo> listProduct = new ArrayList<ProductInfo>();
						for(FavoriteProduct record : listFavor){
							AgentProductInfo agentProduct = shopManager.getLowestPrice(record.getProductID());
							ProductInfo info = productManager.getProductInfo(record.getProductID(), 0);
							info.setSellingPrice(agentProduct.getSellingPrice());
							listProduct.add(info);
						}
						// return favorite or watching product
						productModel.setListProduct(listProduct);
						if(Integer.parseInt(type) == 2){
							return "watchlist";
						}
						return SUCCESS;
					}
				} else {
					return "banned";
				}
			}

	// watch list
	public String mngWatchListLink(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else {
				String type = request.getParameter("type");
				if(session.get("role").equals(4)){
					String userID = session.get("userID").toString();
					List<FavoriteProduct> listFavor = profileManager.getWatchListProduct(Integer.parseInt(userID), Integer.parseInt(type));
					List<ProductInfo> listProduct = new ArrayList<ProductInfo>();
					for(FavoriteProduct record : listFavor){
						ProductInfo info = productManager.getProductInfo(record.getProductID(), 0);
						if(shopManager.getLowestPrice(record.getProductID()) != null){
							AgentProductInfo agentProduct = shopManager.getLowestPrice(record.getProductID());
							info.setSellingPrice(agentProduct.getSellingPrice());
						}
						listProduct.add(info);
					}
					productModel.setListProduct(listProduct);
				}else {
					return "user-home";
				}
				if(type.equals("2")){
					return "watchlist";
				}
				return SUCCESS;
			}
		} else {
			return "banned";
		}
	}
	
	// add favorite product
	public String addFavoriteProduct() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null
				|| session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("role").equals(4)) {
					String productID = request.getParameter("productID");
					String type = request.getParameter("type");
					String userID = session.get("userID").toString();
					FavoriteProduct favor = new FavoriteProduct();
					if (productID != null) {
						favor.setProductID(Integer.parseInt(productID));
						favor.setUserID(Integer.parseInt(userID));
						favor.setType(Integer.parseInt(type));
						ProductInfo info = productManager.getProductInfo(Integer.parseInt(productID), 0);
						productModel.setListAgentProduct(shopManager
								.getListAgentSellingProduct(Integer.parseInt(productID)));
						if (!profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , Integer.parseInt(type))){
							profileManager.addFavoriteProduct(favor);
							if (profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 1)
									 && !profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 2)){
								info.setFavorite(1);
							}else if (!profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 1)
									&& profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 2)){
								info.setFavorite(2);
							}else if (profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 1)
									&& profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 2)){
								info.setFavorite(3);
							}
						}else{
							if (profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 1)
									 && !profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 2)){
								info.setFavorite(1);
							}else if (!profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 1)
									&& profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 2)){
								info.setFavorite(2);
							}else if (profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 1)
									&& profileManager.checkFavoriteProduct(Integer.parseInt(productID), Integer.parseInt(userID) , 2)){
								info.setFavorite(3);
							}
						}
						productModel.setProductInfo(info);
					}
				} else {
					String productID = request.getParameter("productID");
					if (productID != null) {
						productModel.setProductInfo(productManager.getProductInfo(Integer.parseInt(productID), 0));
						productModel.setListAgentProduct(shopManager.getListAgentSellingProduct(Integer.parseInt(productID)));
					}
				}
				productModel.setAutoComplete(productManager.getAutoCompleteList());
				return SUCCESS;
			}
		} else {
			return "banned";
		}
	}

	public String shopManagementByMod() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(3)) {
				profileModel.setListAgent(shopManager.getAllAgent());
				return "success";
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String mngProductShopLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(3)) {
				String id = request.getParameter("agentID");
				Integer agentID = null;
				if(id!= null){
					agentID = Integer.parseInt(id);
				}
				List<ProductList> listShopProduct = shopManager.getAllProductOfShop(agentID);
				List<ProductInfo> listProduct = new ArrayList<ProductInfo>();
				for (ProductList record : listShopProduct) {
					ProductInfo productInfo = new ProductInfo();
					Integer listType = record.getListType();
					Agent_Product agentProduct = shopManager.getAgentProductInfo(record.getListID());
					if (listType == 0) {
						productInfo = productManager.getProductInfo(record.getProductID(), 0);
					} else {
						productInfo = productManager.getProductInfo(record.getProductID(), agentID);
					}
					productInfo.setSellingPrice(agentProduct.getSellingPrice());
					productInfo.setWarranty(agentProduct.getWarranty());
					productInfo.setCondition(agentProduct.getProductCondition());
					productInfo.setStartDate(agentProduct.getStartDate());
					productInfo.setListID(agentProduct.getListID());
					listProduct.add(productInfo);
				}
				productModel.setListProduct(listProduct);
				return "success";
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}
	
	// product Management by shop
	public String productMngByShop() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					ShopInfo shopInfo = (ShopInfo) session.get("shopInfo");
					Integer agentID = shopInfo.getAgentID();
					List<ProductList> listShopProduct = shopManager.getAllProductOfShop(shopInfo.getAgentID());
					List<ProductInfo> listProduct = new ArrayList<ProductInfo>();
					for (ProductList record : listShopProduct) {
						ProductInfo productInfo = new ProductInfo();
						Integer listType = record.getListType();
						// get product info of shop
						Agent_Product agentProduct = shopManager.getAgentProductInfo(record.getListID());
						if(agentProduct != null){
							
							// get discount if have
							Discount discount = shopManager.getDiscount(record.getListID());
							// set product info of web or shop
							if (listType == 0) {
								productInfo = productManager.getProductInfo(record.getProductID(), 0);
							} else {
								productInfo = productManager.getProductInfo(record.getProductID(), agentID);
							}
							// set discount if have
							if(discount != null){
								productInfo.setDiscount(discount.getDiscount());
								float discountPercent = Math.round((float)((((float)agentProduct.getSellingPrice() - (float)discount.getDiscount())  / 
										(float)agentProduct.getSellingPrice())) * 100);
								productInfo.setDiscountPercent(discountPercent);
							}
							productInfo.setSellingPrice(agentProduct.getSellingPrice());
							productInfo.setWarranty(agentProduct.getWarranty());
							productInfo.setCondition(agentProduct.getProductCondition());
							productInfo.setStartDate(agentProduct.getStartDate());
							productInfo.setListID(agentProduct.getListID());
						}
						listProduct.add(productInfo);
					}
					productModel.setListProduct(listProduct);
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}

	// image management link
	public String imgManageLink() {
		Dispatcher.getInstance().getConfigurationManager().reload();
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null
				|| session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2) || session.get("role").equals(5)) {
				if(request.getParameter("productID") == null){
					return "homepage";
				}
				String productID = request.getParameter("productID");
				if (productID != null) {
					Integer imgType = null;
					if (session.get("role").equals(1) || session.get("role").equals(2)) {
						imgType = 0;
					} else if (session.get("role").equals(5)) {
						ShopInfo shopInfo = (ShopInfo) session.get("shopInfo");
						imgType = shopInfo.getAgentID();
					}
					productModel.setProductInfo(productManager.getProductInfo(Integer.parseInt(productID), imgType));
					ProductInfo info = productManager.getProductInfo(Integer.parseInt(productID), imgType);
					List<String> linkImg = info.getListLinkImg();
					Integer i = 5;
					for (String record : linkImg) {
						i--;
					}
					List<String> listFileSubmit = new ArrayList<String>();
					for (Integer j = 0; j < i; j++) {
						listFileSubmit.add("aa");
					}
					if (listFileSubmit != null) {
						productModel.setListFileSubmit(listFileSubmit);
					}
				}
				if (session.get("role").equals(5)) {
					return "shop";
				}
				return "success";
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	// add product link by shop

	public String addShopProductLink() {
		sortType = null;
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					ShopInfo shopInfo = (ShopInfo) session.get("shopInfo");
					sortType = request.getParameter("sortType");
					if (sortType != null) {
						List<ProductInfo> listProduct = productManager.getAllProduct(Integer.parseInt(sortType));
						List<ProductInfo> listProductInfo = new ArrayList<ProductInfo>();
						for(ProductInfo record : listProduct){
							if(shopManager.getProductList(Integer.parseInt(record.getProductID()), shopInfo.getAgentID()) != null){
								record.setListID(shopManager.getProductList(Integer.parseInt(record.getProductID()), 
										shopInfo.getAgentID()).getListID());
							}
							listProductInfo.add(record);
						}
						productModel.setListProduct(listProductInfo);
					}
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}

	public String detailProductLink() {
		productModel.setListSubcat(productManager.listSubCatInfo());
		productModel.setListBrandInfo(productManager.getListBrand());
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {
				String productID = request.getParameter("productID");
				if (productID != null) {
					productModel.setProductInfo(productManager.getProductInfo(Integer.parseInt(productID), 0));
				}
				return "success";
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String manageProductLink() {
		sortType = null;
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {
				sortType = request.getParameter("sortType");
				if (sortType != null) {
					productModel.setListProduct(productManager.getAllProduct(Integer.parseInt(sortType)));
				}
				return "success";
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String changeLogoLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}

	public String changeShopProfileLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}

	public String regShopLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("NotAvail")) {
					return SUCCESS;
				} else {
					return ERROR;
				}
			}
		} else {
			return "banned";
		}
	}

	public String shopLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				if (session.get("shop").equals("Avail")) {
					return SUCCESS;
				} else {
					if(session.get("role").equals(4)){
						return ERROR;
					}else {
						return "homepage";
					}
				}
			}
		} else {
			return "banned";
		}
	}

	public String changePwdLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				return SUCCESS;
			}
		} else {
			return "banned";
		}
	}

	public String changeEmailLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {
			if (session.get("role") == null) {
				return "login";
			} else {
				return SUCCESS;
			}
		} else {
			return "banned";
		}
	}

	public String changeAvatarLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else {
				return SUCCESS;
			}
		} else {
			return "banned";
		}
	}

	public String changeProfileLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else {
				String birthDay = session.get("birthDay").toString();
				String[]tokens = birthDay.split("-");
				String day = tokens[2];
				String month = tokens[1];
				String year = tokens[0];
				profileModel.setDay(day);
				profileModel.setMonth(month);
				profileModel.setYear(year);
				
				return SUCCESS;
			}
		} else {
			return "banned";
		}
	}

	public String forgetPwdLink() {
		return SUCCESS;
	}

	public String userPanelLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else {
				return SUCCESS;
			}
		} else {
			return "banned";
		}
	}

	public String moreProductLink() {
		sortType = null;
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			sortType = request.getParameter("sortType");
			if (sortType != null) {
				Integer sort = Integer.parseInt(sortType);
				List<ProductInfo> listProduct = productManager.getAllProduct(sort);
				productModel.setListProduct(listProduct);
			}
			setListSubCat(productManager.listSubCatInfo());
			return SUCCESS;
		} else {
			return "banned";
		}
	}

	public String detailCategoriesLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {
				productModel.setListSubcat(productManager.listSubCatInfo());
				productModel.setListCategories(productManager.listCategories());
				return SUCCESS;
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String categoriesLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {

				productModel.setListSubcat(productManager.listSubCatInfo());
				productModel.setListMainCategories(productManager.getAllMainCategories());
				return SUCCESS;
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String addModeratorLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1)) {

				return SUCCESS;
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String loginLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return SUCCESS;
			} else {

				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String regLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return SUCCESS;
			} else {

				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String homepageLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			return "success";
		} else {
			return "banned";
		}
	}

	public String adminpageLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2) || session.get("role").equals(3)) {

				return "success";
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String addProductLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {

				List<SubCatInfo> listSubcat = productManager.listSubCatInfo();
				List<Categories> catInfo = productManager.listAllCategories();
				productModel.setListSubcat(listSubcat);
				productModel.setListCategories(catInfo);
				List<BrandInfo> brandInfo = productManager.getListBrand();
				if (brandInfo != null) {
					productModel.setListBrandInfo(brandInfo);
				}
				return "success";
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String addBrandLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {
				productModel.setTabActive1("active");
				productModel.setTabActive2(null);
				List<BrandInfo> brandInfo = productManager.getListBrand();
				if (brandInfo != null) {
					productModel.setListBrandInfo(brandInfo);
				}
				return "success";
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	public String detailBrandLink() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		if (session.get("isBanned") == null || session.get("isBanned").equals(0)) {

			if (session.get("role") == null) {
				return "login";
			} else if (session.get("role").equals(1) || session.get("role").equals(2)) {
				List<BrandInfo> brandInfo = productManager.getListBrand();
				if (brandInfo != null) {
					productModel.setListBrandInfo(brandInfo);
				}
				return SUCCESS;
			} else {
				return ERROR;
			}
		} else {
			return "banned";
		}
	}

	@Override
	public ProductModel getModel() {
		return productModel;
	}

	public ProductModel getProductModel() {
		return productModel;
	}

	public void setProductModel(ProductModel productModel) {
		this.productModel = productModel;
	}

	public ProductManager getProductManager() {
		return productManager;
	}

	public void setProductManager(ProductManager productManager) {
		this.productManager = productManager;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;

	}

	public String getSortType() {
		return sortType;
	}

	public void setSortType(String sortType) {
		this.sortType = sortType;
	}

	public List<SubCatInfo> getListSubCat() {
		return listSubCat;
	}

	public void setListSubCat(List<SubCatInfo> listSubCat) {
		this.listSubCat = listSubCat;
	}

	public ProfileModel getProfileModel() {
		return profileModel;
	}

	public void setProfileModel(ProfileModel profileModel) {
		this.profileModel = profileModel;
	}

	public ProfileManager getProfileManager() {
		return profileManager;
	}

	public void setProfileManager(ProfileManager profileManager) {
		this.profileManager = profileManager;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public ShopManager getShopManager() {
		return shopManager;
	}

	public void setShopManager(ShopManager shopManager) {
		this.shopManager = shopManager;
	}
	
	public ShopModel getShopModel() {
		return shopModel;
	}

	public void setShopModel(ShopModel shopModel) {
		this.shopModel = shopModel;
	}

	public String getLinkBanner() {
		return linkBanner;
	}

	public void setLinkBanner(String linkBanner) {
		this.linkBanner = linkBanner;
	}

	public WebInterface getWebInterface() {
		return webInterface;
	}

	public void setWebInterface(WebInterface webInterface) {
		this.webInterface = webInterface;
	}
	
	public InterfaceManager getInterfaceManager() {
		return interfaceManager;
	}

	public void setInterfaceManager(InterfaceManager interfaceManager) {
		this.interfaceManager = interfaceManager;
	}
	
	public DateTime getDateTime() {
		return dateTime;
	}

	public void setDateTime(DateTime dateTime) {
		this.dateTime = dateTime;
	}


}
